import requests

from requests基础 import headers

video_url='https://vdept3.bdstatic.com/mda-ndc4d1nxgy14nztd/cae_h264_delogo/1649819428555205822/mda-ndc4d1nxgy14nztd.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1744892349-0-0-c721fadf28f98c67c3da9730d001a62e&bcevod_channel=searchbox_feed&pd=1&cr=0&cd=0&pt=3&logid=1149144607&vid=4759456910754957111&klogid=1149144607&abtest='

headers={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0'

}
response=requests.get(video_url,headers=headers,stream=True)
length=response.headers.get('Content-Length')

with open('video3.mp4','ab') as f:
    writed_size=0
    for chunk in response.iter_content(chunk_size=1024):
        writed_size+=f.write(chunk)
        # 使用 f-string 语法
        print(f'下载进度：{100*writed_size/int(length):02.2f}')

        